// pages/feedback/feedback.js

const api = require('../../utils/backendAPI.js');

Page({

  data: {
    feedback: {
      feedback: '',
      contact: '',
    },
    version: '1.2.6',
    newest: '',
  },
  onLoad: function (options) {
    ret = api.checkUpdate()
    if (ret == "false") {
      this.setData({
        newest: '已是最新版本'
      })
    }
    else if (ret == "true") {
      this.setData({
        newest: '有新版本，请关闭小程序后重新打开以进行更新'
      })
    }
    else {
      //invalid
      this.setData({
        newest: '版本更新检查不可用'
      })
    }
  },

  focusFeedback: function () {
    this.setData({ feedbackFocus: true })
  },
  inputHandler: function (e) {
    this.data.feedback[e.currentTarget.dataset.item] = e.detail.value
  },
  submitFeedback: function (e) {
    wx.showLoading({
      title: '正在提交'
    })
    api.uploadFeedback({
      feedback: this.data.feedback.feedback,
      contact: this.data.feedback.contact
    }).then((res) => {
      wx.hideLoading()
      wx.navigateBack()
      wx.showToast({
        title: '感谢反馈',
      })
    }).catch(e => {
      wx.hideLoading()
      wx.showToast({
        title: e.errMsg,
        icon: 'none'
      })
    })
  },

  onShareAppMessage: function (res) {
    return {
      title: '快来看看学长开发的万能基物实验小程序！',
      path: 'pages/index/index',
      imageUrl: 'https://s1.ax1x.com/2020/07/25/aSICY4.jpg',
      success: function (res) {
        console.log('成功分享', res)
      }
    }
  }
}) 